<template>
	<view>
		<view class="navbar" style="padding: 20rpx;height: 180rpx;background-color: #fff;">
			<view class="title" style="text-align: center;color: #dd6161;font-size: 45rpx;font-weight: bold;">服务页</view>
			<view class="search" style="width: 95%;height: 64rpx;margin: 20rpx auto;flex-shrink: 0;display: flex;
			flex-direction: row;justify-content: start;align-items: center;background-color: #f2f2f2;border: 2rpx solid #dd6161;
			border-radius: 50rpx;position: relative;">
				<u-icon name="search" style="margin-left: 20rpx;"></u-icon>
				<input type="text" placeholder="请输入关键字" style="margin-left: 20rpx;" v-model="value">
				<button @click="submit" style="width: 120rpx;height: 95%;color: white;background-color: #fa3534;font-size: 28rpx;
				display: flex;justify-content: center;align-items: center;position: absolute;right: 1rpx;top: 1rpx;border-radius: 50rpx;">搜索</button>
			</view>
		</view>
		<view class="main">
			<scroll-view scroll-y="true" class="left">
				<view class="tab-list">
					<view class="tab-item" v-for="(item, index) in tabList" @click="tabChange(index)" :class="activeIndex === index ? 'active' : ''">{{item}}</view>
				</view>
			</scroll-view>
			<scroll-view scroll-y="true" class="right">
				<view class="cate">
					<view class="cate-item" v-for="item in selectList">
						<image :src="$baseUrl + item.imgUrl" mode=""></image>
						<text>{{item.serviceName}}</text>
					</view>
				</view>
			</scroll-view>
		</view>
		<u-popup class="popup" mode="bottom" v-model="show">
			<view class="content">
				<view class="cate">
					<view class="cate-item" v-for="item in searchList">
						<image :src="$baseUrl + item.imgUrl" mode=""></image>
						<text>{{item.serviceName}}</text>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabList: [],
				serviceList: [],
				activeIndex: 0,
				selectList:[],
				value: '',
				show: false,
				searchList: []
			};
		},
		onLoad() {
			this.getServie()
		},
		methods: {
			getServie(){
				this.$request({
					url: '/prod-api/api/service/list'
				}).then(res => {
					console.log(res)
					this.serviceList = res.rows
					this.getTab()
				})
			},
			getTab(){
				this.tabList = new Set(this.serviceList.filter(item => item.serviceType !== null).map(item => item.serviceType))
				this.tabList = Array.from(this.tabList)
				console.log(this.tabList)
				this.getSelect()
			},
			tabChange(index){
				this.activeIndex = index
				this.getSelect()
			},
			getSelect(){
				this.selectList = this.serviceList.filter(item => item.serviceType === this.tabList[this.activeIndex])
				console.log(this.selectList)
			},
			submit(){
				this.show = true
				this.searchList = this.serviceList.filter(item => item.serviceName.includes(this.value))
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		height: 100%;
		view{
			height: 100%;
			display: flex;
			flex-direction: column;
			.main{
				flex: 1;
				display: flex;
				flex-direction: row;
				.left{
					width: 200rpx;
					background-color: #f7f7f7;
					.tab-list{
						.tab-item{
							height: 96rpx;
							padding: 20rpx;
							display: flex;
							justify-content: center;
							align-items: center;
							position: relative;
							&::before{
								content: '';
								border-top: 2rpx solid #e4e7ed;
								width: 50%;
								left: 25%;
								bottom: 0;
								position: absolute;
							}
						}
						.active{
							color: #dd6161;
							font-size: 36rpx;
							font-weight: bold;
							&::after{
								content: '';
								width: 8rpx;
								height: 100%;
								position: absolute;
								left: 0;
								top: 0;
								background-color: #dd6161;
							}
						}
					}
				}
				.right{
					flex: 1;
					.cate{
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						justify-content: start;
						padding: 20rpx;
						height: fit-content;
						.cate-item{
							padding: 20rpx;
							display: flex;
							flex-direction: column;
							justify-content: center;
							align-items: center;
							width: 120rpx;
							height: fit-content;
							image{
								width: 100rpx;
								height: 100rpx;
							}
							text{
								width: 120rpx;
								white-space: nowrap;
								text-overflow: ellipsis;
								overflow: hidden;
								font-size: 26rpx;
								color: #666;
								margin-top: 10rpx;
								text-align: center;
							}
							.icon{
								width: 100rpx;
								height: 100rpx;
								border-radius: 50%;
								border: 4rpx solid #2979ff;
								display: flex;
								justify-content: center;
								align-items: center;
							}
						}
					}
				}
			}
			.popup{
				.content{
					.cate{
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						justify-content: space-between;
						align-items: center;
						padding: 20rpx;
						.cate-item{
							padding: 20rpx;
							display: flex;
							flex-direction: column;
							justify-content: center;
							align-items: center;
							width: 120rpx;
							height: fit-content;
							image{
								width: 100rpx;
								height: 100rpx;
							}
							text{
								width: 120rpx;
								white-space: nowrap;
								text-overflow: ellipsis;
								overflow: hidden;
								font-size: 26rpx;
								color: #666;
								margin-top: 10rpx;
								text-align: center;
							}
							.icon{
								width: 100rpx;
								height: 100rpx;
								border-radius: 50%;
								border: 4rpx solid #2979ff;
								display: flex;
								justify-content: center;
								align-items: center;
							}
						}
					}
				}
			}
			}
	}
</style>
